package net.noday.web;

import java.util.HashMap;
import java.util.Map;

import net.noday.domain.User;
import net.noday.service.impl.WebApplicationServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DefaultConroller {

	@Autowired
	private WebApplicationServiceImpl webApplicationService;
	
	@RequestMapping("/")//root
	public String test(ModelMap model) {
		model.put("app", webApplicationService.get());
		User user = new User();
		user.setEmail("at1943@noday.net");
		model.put("user", user);
		return "homepage";
	}
	
	@RequestMapping(value = "/json/index", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Map<String, User>> getJson2() {
		Map<String, User> user = new HashMap<String, User>();
		User u1 = new User();
		User u2 = new User();
		u1.setEmail("at1943@163.com");
		u1.setUid(1);
		u2.setEmail("at1943@126.com");
		u2.setUid(2);
		user.put("u1", u1);
		user.put("u2", u2);

		Map<String, Map<String, User>> root = new HashMap<String, Map<String, User>>();
		root.put("root", user);
		return root;
	}
}
